******************************************************
* Analyse data
* 
* The Economic Consequences of Being Widowed by War: A Life-cycle Perspective
* Sebastian Braun and Jan Stuhler
* Journal of Public Economics, 2024, Vol. 239
* Dataset: GHS-1, GHS-2
*
* Figures: 1, E-1, E-2
* Tables:  4, E-2
******************************************************

***********************
*** Figures
***********************

* Keep only data from GHS-2 (birth cohorts 1919-21)
use "$widowsghs/processed/GHS_widows_data_main.dta", clear
keep if kohorte == 1

* Define additional variables

* Birth year x age interactions
egen gebXalterAll=group(geburtsjahr alter_j) 

* Occupational prestige conditional on working
gen beruf_prestige_cond_t=beruf_prestige_t if beruf_prestige_t!=0

* Collapse data on age-in-years level
order ___Panel_IDs________________ fid t monat jahr alter_j alter_t lv2 
foreach l of var * {
	local `l' : variable label `l'
} 
collapse (min) t monat jahr (first) alter_t lv2 (mean) geburtsjahr-beruf_prestige_cond_t , by(fid alter_j)
foreach v of var * {
	label var `v' `"``v''"'
}
sort fid alter_j
by fid: gen fid_n=_n
order fid fid_n

* Keep only women married before 1945
gen married_b_1945 = 0
replace married_b_1945 = 1 if heiratsjahr_2002 <= 1945 & heiratsjahr_2002 != .
keep if geschlecht==2 & married_b_1945 == 1

* Lost spouse in war?
recode todesjahr_2002 95 = 1945 // 95 = Im Krieg vermisst
gen death_spouse_b_1945 = 0
replace death_spouse_b_1945 = 1 if todesjahr_2002 <= 1945 & todesjahr_2002 != .

* Optionally, also condition on having a child before 1945
bysort fid: gen tmp=(anzahl_kinder_t>=1 & jahr<=1945)
bysort fid: egen kids_b_1945=max(tmp)
drop tmp
gen death_spouse_b_1945_kids=death_spouse_b_1945 if kids_b_1945==1

* Define analysis range for each outcome

* Education
foreach var of varlist schule_t {  
 global LB_`var'=0
 global UB_`var'=20
}
foreach var of varlist /*d_lmstates3_1*/ ausbildung_t dienst_t { 
 global LB_`var'=0
 global UB_`var'=35
}
* Employment / Labor market
foreach var of varlist /*d_lmstates3_2 d_lmstates3_3*/ erwerbstaetig_t /*fulltime_t*/ spell_no_t wochenstunden_beruf_t endverdienst_t /*erwerbstaetig_nofam_t outside_agriculture_t d_sector_t_1 d_sector_t_2 d_sector_t_3 d_occupation_t_**/  { 
 global LB_`var'=18
 global UB_`var'=65
}
foreach var of varlist beruf_prestige_t beruf_prestige_cond_t {  
 global LB_`var'=18
 global UB_`var'=62
}
* Marriage and children
foreach var of varlist verheiratet_t anzahl_kinder_t ehenr_t {  
 global LB_`var'=14
 global UB_`var'=65
}
* Illness and other
foreach var of varlist illness_t /*wohnwechsel_t*/  {  
 global LB_`var'=0
 global UB_`var'=65
}

* Define shadings WW2
global shadeWW2k1 "19 19.2 19.4 19.6 19.8 20 20.2 20.4 20.6 20.8 21 21.2 21.4 21.6 21.8 22 22.2 22.4 22.6 22.8 23 23.2 23.4 23.6 23.8 24 24.2 24.4 24.6 24.8 25"



*** Figure 1: Life-cycle effects of war widowhood (GHS)
*** Paenls a-d (panels e-f are based on different cohorts, see below)  

foreach var of varlist verheiratet_t anzahl_kinder_t erwerbstaetig_t beruf_prestige_cond_t { 
	
	if "`var'"=="verheiratet_t" local panel="a"
	if "`var'"=="anzahl_kinder_t" local panel="b"
	if "`var'"=="erwerbstaetig_t" local panel="c"
	if "`var'"=="beruf_prestige_cond_t" local panel="d"
	
	* We residualize first by heiratsjahr 
	reg `var' i.alter_j i.alter_j#c.heiratsjahr_2002 if kohorte==1 & geschlecht==2 & death_spouse_b_1945!=. , ro
	predict `var'_r , res
	
	* Lifecycle effects and plot
	areg `var'_r i.alter_j#c.death_spouse_b_1945 if alter_j>=${LB_`var'} & alter_j<=${UB_`var'} & kohorte==1 & geschlecht==2 , /// 
		vce(robust) absorb(gebXalterAll) 
	gen g_age=.
	gen g_coef=.
	gen g_ub=.
	gen g_lb=.
	forval i=${LB_`var'}/${UB_`var'} {
		local j=`i'+1
		cap replace g_age=`i' in `j'
		cap replace g_coef=_b[`i'.alter_j#c.death_spouse_b_1945] in `j'
		cap replace g_ub=_b[`i'.alter_j#c.death_spouse_b_1945] + invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j#c.death_spouse_b_1945] in `j'
		cap replace g_lb=_b[`i'.alter_j#c.death_spouse_b_1945] - invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j#c.death_spouse_b_1945] in `j'
	}
	twoway 	(scatter g_coef g_age if g_age>=${LB_`var'} & g_age<=${UB_`var'} , connect(l) color(dknavy) msymbol(S)) ///
			(rcap g_ub g_lb g_age , lwidth(thin) lcolor(dknavy))	///
			, xlabel(#10) xline($shadeWW2k1, lcolor(gs14)) yline(0, lwidth(vthin) lcolor(gs8)) graphregion(color(white)) legend(off) xtitle(age) /*note("${valdistr}")*/
	drop g_*
	drop `var'_r			
	graph save "$widowsghs/results/figures/Fig1_panel_`panel'.gph" , replace 
	graph export "$widowsghs/results/figures/Fig1_panel_`panel'.pdf" , replace 
} 

*** Figure E1: Illness over the life-cycle

* Note: In the published Appendix, the variable "illness_t" contained a coding error (missings were coded as zeroes).
* Fixing this error affected the range of the y-axis, but otherwise leads to the same lifeycle pattern and conclusions.

binscatter illness_t alter_j if alter_j>=18 & alter_j<=63 & geschlecht==2, ///
	by(death_spouse_b_1945_kids) discrete xlabel(20(5)60) xtitle("Age") linetype(connect) name(k1, replace) xline($shadeWW2k1, lcolor(gs14)) /// 
	legend(lab(2 "War widows") lab(1 "Non-widows") region(color(none))) ytitle("Illness")
graph save "$widowsghs/results/figures/FigE1.gph" , replace 
graph export "$widowsghs/results/figures/FigE1.pdf" , replace 


*** Figure E2: Employment rate of war widows around the remarriage year

* Add data on marriage year for second spouse
merge m:1 fid using "$widowsghs/processed/LVII_CS_combined_edt.dta" , ///
	keepusing(heiratsjahr_2003)
drop _merge
tab heiratsjahr_2002 if kohorte==1 & geschlecht==2 & death_spouse_b_1945!=. &alter_j==0 , miss	// first marriage
tab heiratsjahr_2003 if kohorte==1 & geschlecht==2 & death_spouse_b_1945==1 &alter_j==0 , miss
tab heiratsjahr_2003 if kohorte==1 & geschlecht==2 & death_spouse_b_1945==0 &alter_j==0 , miss 

gen d_heiratsjahr_2003 = jahr-heiratsjahr_2003
binscatter erwerbstaetig_t d_heiratsjahr_2003 if d_heiratsjahr_2003>=-8 & d_heiratsjahr_2003<=8 & death_spouse_b_1945_kids==1, /// 
	discrete /*xlabel(20(5)60)*/ xtitle("Year relative to re-marriage") linetype(connect) name(k1, replace) xline(-0.5,lcolor(red)) /// 
	legend(lab(2 "War widows") lab(1 "Non-widows") region(color(none))) ytitle("Employment") ylabel(0.2(0.1)0.7, gmax gmin) xlabel(-8(2)8) xmtick(-8(1)8)
graph save "$widowsghs/results/figures/FigE2.gph" , replace 
graph export "$widowsghs/results/figures/FigE2.pdf" , replace 



*** Figure 1: Life-cycle effects of war widowhood (GHS)
*** Panels e-f

* Load data
use "$widowsghs/processed/GHS_widows_data_main.dta", clear

* Define additional variables

* Birth year x age interactions
egen gebXalterAll=group(geburtsjahr alter_j) 

* Occupational prestige conditional on working
gen beruf_prestige_cond_t=beruf_prestige_t if beruf_prestige_t!=0

* Generate unemployment and (non-)participation variables
gen unemployed_t = 0
replace unemployed_t = 1 if (luecke_se_aktivitität_t == 30 | erwerbsluecke_taetigkeit_t == 30)
label var unemployed_t "AAL05/ABL01: Unemployed/no apprenticeship at time t?"

gen participation_t = 0
replace participation_t = 1 if (unemployed_t == 1 | erwerbstaetig_t == 1)
label var participation_t "Employed or unemployed at time t?"

gen non_participation_t = 0
replace non_participation_t = 1 if (participation_t == 0 & schule_t == 0 & ausbildung_t == 0)
label var non_participation_t "Out of labor force, not in education at time t"

gen in_school_or_education_t = schule_t + ausbildung_t
replace in_school_or_education_t = 1 if in_school_or_education_t == 2 

gen	labor_market_state = .
replace labor_market_state = 1 if in_school_or_education_t == 1 
replace labor_market_state = 2 if participation_t == 1
replace labor_market_state = 3 if non_participation_t == 1

label define states3 1 "In education" 2 "Labor market participation" 3 "Out of labor force"
label values labor_market_state states3
tab labor_market_state, gen(d_lmstates3_)

* Collapse data on age-in-years level
order ___Panel_IDs________________ fid t monat jahr alter_j alter_t lv2 
foreach l of var * {
	local `l' : variable label `l'
} 
collapse (min) t monat jahr (first) alter_t lv2 (mean) geburtsjahr-d_lmstates3_3 , by(fid alter_j)
foreach v of var * {
	label var `v' `"``v''"'
}
sort fid alter_j
by fid: gen fid_n=_n
order fid fid_n

* Define shocks for selected sample (condition on father being absent during the war) 
gen sample_tod_vater=(kohorte>=2 & kohorte<=3 & vater_jahre_abw_krieg>0 & vater_jahre_abw_krieg<. & todesjahr_mutter>1945)
gen tod_vater_krieg_v1c=tod_vater_krieg_v1 if sample_tod_vater==1
gen tod_vater_krieg_v2c=tod_vater_krieg_v2 if sample_tod_vater==1

* Age variable 
cap drop alter_j2
gen alter_j2=2*ceil(alter_j/2)

* Men K2+K3, education and employment
areg d_lmstates3_1 i.alter_j2#c.tod_vater_krieg_v1c if alter_j>=8 & alter_j<=32 & (kohorte==2 | kohorte==3) & geschlecht==1 , /// 
	vce(robust) absorb(gebXalterAll) 
gen g_age=.
gen g_coef_1=.
gen g_ub_1=.
gen g_lb_1=.
forval i=8/32 {
	local j=`i'+1
	cap replace g_age=`i' -0.3 in `j'
	cap replace g_coef_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_ub_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] + invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_lb_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] - invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
}
areg erwerbstaetig_t i.alter_j2#c.tod_vater_krieg_v1c if alter_j>=14 & alter_j<=40 & (kohorte==2 | kohorte==3) & geschlecht==1 , /// 
	vce(robust) absorb(gebXalterAll) 
gen g_age_2=.
gen g_coef_2=.
gen g_ub_2=.
gen g_lb_2=.
forval i=14/39 {
	local j=`i'+1
	cap replace g_age_2=`i'+0.7 in `j'
	cap replace g_coef_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_ub_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] + invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_lb_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] - invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
}
twoway 	(scatter g_coef_1 g_age if g_age>=7.5 & g_age<=30 , connect(l) color(dknavy) msymbol(S)) ///
				(rcap g_ub_1 g_lb_1 g_age if g_age>=7.5 & g_age<=30 , lwidth(thin) lcolor(dknavy))	///
				(scatter g_coef_2 g_age_2 if g_age_2>=14 & g_age_2<=40.5 , connect(l) color(dkorange) msymbol(D)) ///
				(rcap g_ub_2 g_lb_2 g_age_2 if g_age_2>=14 & g_age_2<=40.5, lwidth(thin) lcolor(dkorange))	///		
		, xlabel(#10)  graphregion(color(white)) yline(0, lwidth(vthin) lcolor(gs8)) ///
		legend(ring(0) position(5) label(1 "Education") label(3 "Employment") bmargin(medium) order(1 3) cols(1) region(lcolor(white))) ///				
		xsize(3) ysize(2.5) ///
		xtitle(age) xlabel(8(4)40) ylabel(-0.3(0.15)0.32) 
graph export "$widowsghs/results/figures/Fig1_panel_e.pdf" , replace
graph save   "$widowsghs/results/figures/Fig1_panel_e.gph" , replace	 		
drop g_*

* Women K2+K3, education and employment
areg d_lmstates3_1 i.alter_j2#c.tod_vater_krieg_v1c if alter_j>=8 & alter_j<=32 & (kohorte==2 | kohorte==3) & geschlecht==2 , /// 
	vce(robust) absorb(gebXalterAll) 
gen g_age=.
gen g_coef_1=.
gen g_ub_1=.
gen g_lb_1=.
forval i=8/32 {
	local j=`i'+1
	cap replace g_age=`i' +0.3 in `j'
	cap replace g_coef_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_ub_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] + invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_lb_1=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] - invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
}
areg erwerbstaetig_t i.alter_j2#c.tod_vater_krieg_v1c if alter_j>=14 & alter_j<=40 & (kohorte==2 | kohorte==3) & geschlecht==2 , /// 
	vce(robust) absorb(gebXalterAll)
gen g_age_2=.
gen g_coef_2=.
gen g_ub_2=.
gen g_lb_2=.
forval i=14/39 {
	local j=`i'+1
	cap replace g_age_2=`i'+0.7 in `j'
	cap replace g_coef_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_ub_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] + invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
	cap replace g_lb_2=_b[`i'.alter_j2#c.tod_vater_krieg_v1c] - invttail(e(df_r),0.5*(1-95/100))*_se[`i'.alter_j2#c.tod_vater_krieg_v1c] in `j'
}	
			
global shadeWW2k2 "9 9.2 9.4 9.6 9.8 10 10.2 10.4 10.6 10.8 11 11.2 11.4 11.6 11.8 12 12.2 12.4 12.6 12.8 13 13.2 13.4 13.6 13.8 14 14.2 14.4 14.6 14.8 15"
twoway 	(scatter g_coef_1 g_age if g_age>=7.5 & g_age<=30 , connect(l) color(dknavy) msymbol(S)) ///
				(rcap g_ub_1 g_lb_1 g_age if g_age>=7.5 & g_age<=30 , lwidth(thin) lcolor(dknavy))	///
				(scatter g_coef_2 g_age_2 if g_age_2>=14 & g_age_2<=40.5 , connect(l) color(dkorange) msymbol(D)) ///
				(rcap g_ub_2 g_lb_2 g_age_2 if g_age_2>=14 & g_age_2<=40.5, lwidth(thin) lcolor(dkorange))	///		
		, xlabel(#10) graphregion(color(white)) yline(0, lwidth(vthin) lcolor(gs8)) ///
		legend(ring(0) position(5) label(1 "Education") label(3 "Employment") bmargin(medium) order(1 3) cols(1) region(lcolor(white))) ///
		xsize(3) ysize(2.5) ///
		xtitle(age) xlabel(8(4)40) ylabel(-0.3(0.15)0.32)
graph export "$widowsghs/results/figures/Fig1_panel_f.pdf" , replace
graph save   "$widowsghs/results/figures/Fig1_panel_f.gph" , replace	 		
drop g_*







******************
*** Tables
******************


**# Table 4: Intergenerational spillovers on the children of war widows
* Load data
use "$widowsghs/processed/GHS_widows_data_main.dta", clear

* Define additional variables

* Birth year x age interactions
egen gebXalterAll=group(geburtsjahr alter_j) 

* Occupational prestige conditional on working
gen beruf_prestige_cond_t=beruf_prestige_t if beruf_prestige_t!=0

* Generate unemployment and (non-)participation variables
gen unemployed_t = 0
replace unemployed_t = 1 if (luecke_se_aktivitität_t == 30 | erwerbsluecke_taetigkeit_t == 30)
label var unemployed_t "AAL05/ABL01: Unemployed/no apprenticeship at time t?"

gen participation_t = 0
replace participation_t = 1 if (unemployed_t == 1 | erwerbstaetig_t == 1)
label var participation_t "Employed or unemployed at time t?"

gen non_participation_t = 0
replace non_participation_t = 1 if (participation_t == 0 & schule_t == 0 & ausbildung_t == 0)
label var non_participation_t "Out of labor force, not in education at time t"

gen in_school_or_education_t = schule_t + ausbildung_t
replace in_school_or_education_t = 1 if in_school_or_education_t == 2 

gen	labor_market_state = .
replace labor_market_state = 1 if in_school_or_education_t == 1 
replace labor_market_state = 2 if participation_t == 1
replace labor_market_state = 3 if non_participation_t == 1

label define states3 1 "In education" 2 "Labor market participation" 3 "Out of labor force"
label values labor_market_state states3
tab labor_market_state, gen(d_lmstates3_)

* Collapse data on age-in-years level
order ___Panel_IDs________________ fid t monat jahr alter_j alter_t lv2 
foreach l of var * {
	local `l' : variable label `l'
} 
collapse (min) t monat jahr (first) alter_t lv2 (mean) geburtsjahr-d_lmstates3_3 , by(fid alter_j)
foreach v of var * {
	label var `v' `"``v''"'
}
sort fid alter_j
by fid: gen fid_n=_n
order fid fid_n

* Define shocks for selected sample (condition on father being absent during the war) 
gen sample_tod_vater=(kohorte>=2 & kohorte<=3 & vater_jahre_abw_krieg>0 & vater_jahre_abw_krieg<. & todesjahr_mutter>1945)
gen tod_vater_krieg_v1c=tod_vater_krieg_v1 if sample_tod_vater==1
gen tod_vater_krieg_v2c=tod_vater_krieg_v2 if sample_tod_vater==1


* Employment at different ages (age 39 and 49 are last ages for observed in cohort 2 and 3, respectively)
gen tmp=erwerbstaetig_t if alter_j>=16 & alter_j<=29
bysort fid: egen erwerbstaetig_1629=total(tmp)
drop tmp

gen tmp=erwerbstaetig_t if alter_j>=25 & alter_j<=29
bysort fid: egen erwerbstaetig_2529=total(tmp)
drop tmp

gen tmp=erwerbstaetig_t if alter_j>=25 & alter_j<=39
bysort fid: egen erwerbstaetig_2539=total(tmp)
drop tmp

gen tmp=erwerbstaetig_t if alter_j>=25 & alter_j<=49
bysort fid: egen erwerbstaetig_2549=total(tmp)
drop tmp

gen tmp=erwerbstaetig_t if alter_j>=30 & alter_j<=39
bysort fid: egen erwerbstaetig_3039=total(tmp)
drop tmp

gen tmp=erwerbstaetig_t if alter_j>=30 & alter_j<=49
bysort fid: egen erwerbstaetig_3049=total(tmp)
drop tmp

local empvars "erwerbstaetig_1629 erwerbstaetig_2529 erwerbstaetig_2539 erwerbstaetig_2549 erwerbstaetig_3039 erwerbstaetig_3049"
local empvars_ "erwerbstaetig_1629_ erwerbstaetig_2529_ erwerbstaetig_2539_ erwerbstaetig_2549_ erwerbstaetig_3039_ erwerbstaetig_3049_"

* Keep one record per person and merge siblings
keep if alter_j==0 
drop fid_n alter*	
merge m:1 fid using "$widowsghs/processed/intermediate/LVIPa_CS_combined_edt.dta" 	
tab _merge if kohorte>=2 & kohorte<=3 
drop if _merge==2
drop _merge

* Define never worked (depending on what code 0 stands for, so two different definitions)
forval num=2011/2019 {
	gen beruf_never0_`num'= (stellung_beruf_jetzt_`num'==0 | stellung_beruf_jetzt_`num'==80 | stellung_beruf_jetzt_`num'==81 & stellung_beruf_jetzt_`num'==82 | stellung_beruf_jetzt_`num'==85) if stellung_beruf_jetzt_`num'<.
	gen beruf_never_`num'=																	(stellung_beruf_jetzt_`num'==80 | stellung_beruf_jetzt_`num'==81 & stellung_beruf_jetzt_`num'==82 | stellung_beruf_jetzt_`num'==85) if stellung_beruf_jetzt_`num'!=0 & stellung_beruf_jetzt_`num'<.
}

* Select variables
drop stellung_beruf_jetzt_2* familienstand_2* berufsausbildung_2* schulabschluss_2*
keep fid-beruf_prestige_max schuljahre_o_uni `empvars' geburtsjahr_1001 geburtsjahr_1002 todesjahr_1002 schuljahre_m_uni_1001 schuljahre_m_uni_1002 tod_vater_krieg_v2c tod_vater_krieg_v1c *2002 *2011 *2012 *2013 *2014 *2015 *2016 *2017 *2018 *2019

* Add the index person him or herself
foreach var of varlist schuljahre_o_uni schuljahre_m_uni ausbildungsjahre geburtsjahr geschlecht `empvars' beruf_prestige_max  {
	ren `var' `var'_2001 
}
* Reshape long
reshape long geschlecht_ geburtsjahr_ todesjahr_ kinder_anzahl_ beruf_never_ beruf_never0_ schuljahre_o_uni_ schuljahre_m_uni_ ausbildungsjahre_ `empvars_' beruf_prestige_max_  /// 
		, i(fid) j(kin 2001 2002 2011 2012 2013 2014 2015 2016 2017 2018 2019)
ren *_ *_kin 
gen kinindexsib=1 if kin==2001 | (kin>=2011 & kin<=2019)		

* Additional variables
bysort fid: egen geburtsjahr_2001=mean(geburtsjahr_kin*cond(kin==2001,1,.,.))
bysort fid: egen geschlecht_2001=mean(geschlecht_kin*cond(kin==2001,1,.,.))
gen Dausbildungsjahre_kin=ausbildungsjahre_kin-schuljahre_o_uni_kin	// tertiary education 

est drop _all
foreach var of varlist *_kin {	
	if "`var'"!="geschlecht_kin" & "`var'"!="geburtsjahr_kin" & "`var'"!="todesjahr_kin"  {
	di "`var'"
	reg `var' tod_vater_krieg_v1c 2.geschlecht_kin#c.tod_vater_krieg_v1c i.geschlecht_kin#i.geburtsjahr_kin geburtsjahr_1002 if kohorte>=2 & kohorte<=3 & kinindexsib==1 & geburtsjahr_kin<=1945 , vce(cluster fid)
	est store e_`var'	
	su `var' if tod_vater_krieg_v1c==0 & e(sample)==1
	estadd scalar mean=r(mean) , replace
	estadd scalar meanobs=r(N) , replace				
	reg `var' tod_vater_krieg_v1c 2.geschlecht_kin#c.tod_vater_krieg_v1c i.geschlecht_kin#i.geburtsjahr_kin geburtsjahr_1002  schuljahre_m_uni_1002 if kohorte>=2 & kohorte<=3 & kinindexsib==1 & geburtsjahr_kin<=1945  , vce(cluster fid)
	est store b_`var'	
	su `var' if tod_vater_krieg_v1c==0 & e(sample)==1
	estadd scalar mean=r(mean) , replace
	estadd scalar meanobs=r(N) , replace			
	areg `var' 2.geschlecht_kin#c.tod_vater_krieg_v1c i.geschlecht_kin#i.geburtsjahr_kin if kohorte>=2 & kohorte<=3 & kinindexsib==1 & geburtsjahr_kin<=1945  , vce(cluster fid) absorb(fid)
	est store x_`var'
	su `var' if tod_vater_krieg_v1c==0 & e(sample)==1
	estadd scalar mean=r(mean) , replace
	estadd scalar meanobs=r(N) , replace			
	}
}	
* Partners	
foreach var of varlist schuljahre_o_uni_kin Dausbildungsjahre_kin ausbildungsjahre_kin beruf_prestige_max_kin {		
	reg `var' tod_vater_krieg_v1c 2.geschlecht_2001#c.tod_vater_krieg_v1c i.geschlecht_2001#i.geburtsjahr_2001 geburtsjahr_1002 if kohorte>=2 & kohorte<=3 & kin==2002 & geburtsjahr_2001<=1945 , vce(cluster fid)
	est store p_`var'	
	su `var' if tod_vater_krieg_v1c==0 & e(sample)==1
	estadd scalar mean=r(mean) , replace
	estadd scalar meanobs=r(N) , replace		
}
* Selected outcomes
estout e_schuljahre_o_uni_kin e_Dausbildungsjahre_kin e_ausbildungsjahre_kin e_erwerbstaetig_1629_kin e_erwerbstaetig_3039_kin e_beruf_prestige_max_kin p_beruf_prestige_max_kin ///
	using "$widowsghs/results/tables/Tab4.csv", legend prehead("Death father tod_vater_krieg_v1c with interaction") cells(b(star fmt(3)) se(par(`"="("'`")""') fmt(3)))  mlabels(,depvars) /// 
	replace starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 N mean meanobs) keep(tod_vater_krieg_v1c *.geschlecht_kin#c.tod_vater_krieg_v1c)


*** Table E2: Exogeneity of war widowhood in GHS

* Load cross-sectional data from GHS-2
use "$widowsghs/processed/LVII_CS_combined_edt.dta", clear
est drop _all

* Keep only women married before 1945
gen married_b_1945 = 0
replace married_b_1945 = 1 if heiratsjahr_2002 <= 1945 & heiratsjahr_2002 != .

keep if geschlecht_2001==2 & married_b_1945 == 1

* Lost spouse in war?
recode todesjahr_2002 95 = 1945 // 95 = missing in action
gen death_spouse_b_1945 = 0
replace death_spouse_b_1945 = 1 if todesjahr_2002 <= 1945 & todesjahr_2002 != .

* Column (1)
reg death_spouse_b_1945 /// 
	geburtsjahr_2001 anz_geschwister_2001 schuljahre_o_uni_2001, ro 
estout using "$widowsghs/results/tables/TabE2.csv", legend cells(b(star fmt(3)) se(par(`"="("'`")""') fmt(3)))  mlabels(,depvars) replace starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N)

* Column (2)
reg death_spouse_b_1945 ///  
	geburtsjahr_2001 anz_geschwister_2001 schuljahre_o_uni_2001 geburtsjahr_2002 schuljahre_o_uni_2002, ro 
estout using "$widowsghs/results/tables/TabE2.csv", legend cells(b(star fmt(3)) se(par(`"="("'`")""') fmt(3)))  mlabels(,depvars) append starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N)

* Column (3)
reg death_spouse_b_1945 /// 
	geburtsjahr_2001 anz_geschwister_2001 schuljahre_o_uni_2001 geburtsjahr_2002 schuljahre_o_uni_2002 heiratsjahr_2002, ro 
estout using "$widowsghs/results/tables/TabE2.csv", legend cells(b(star fmt(3)) se(par(`"="("'`")""') fmt(3)))  mlabels(,depvars) append starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N)

* Column (4)
reg death_spouse_b_1945 /// 
	geburtsjahr_2001 anz_geschwister_2001 schuljahre_o_uni_2001 geburtsjahr_2002 schuljahre_o_uni_2002 heiratsjahr_2002 ///
	schuljahre_m_uni_1001 schuljahre_m_uni_1002 beruf_prestige_max_tr_1001, ro 
estout using "$widowsghs/results/tables/TabE2.csv", legend cells(b(star fmt(3)) se(par(`"="("'`")""') fmt(3)))  mlabels(,depvars) append starlevels(* 0.10 ** 0.05 *** 0.01) stats(r2 r2_a N)
	
* Means
tabstat geburtsjahr_2001 anz_geschwister_2001 schuljahre_o_uni_2001 schuljahre_o_uni_2002 geburtsjahr_2002 heiratsjahr_2002 ///
	schuljahre_m_uni_1001 schuljahre_m_uni_1002 beruf_prestige_max_tr_1001, stat(mean sd N) 
	
*** EOF
	
